Trò chơi Pac-Man

20.577 lượt xem;
1 using System.Collections.Generic;
2 using
UnityEngine;
3 using
UnityEngine.UI;
4
5 public
class UIScript : MonoBehaviour {
6
7     
public int high, score;
8
9     
public List<Image> lives = new List<Image>(3);
10
11     Text txt_score, txt_high, txt_level;
12     
13     
// Use this for initialization
14     
void Start ()
15     {
16         txt_score = GetComponentsInChildren<Text>()[
1];
17         txt_high = GetComponentsInChildren<Text>()[
0];
18         txt_level = GetComponentsInChildren<Text>()[
2];
19
20         
for (int i = 0; i < 3 - GameManager.lives; i++)
21         {
22             Destroy(lives[lives.Count-
1]);
23             lives.RemoveAt(lives.Count-
1);
24         }
25     }
26     
27     
// Update is called once per frame
28     
void Update ()
29     {
30
31         high = GameObject.Find(
"Game Manager").GetComponent<ScoreManager>().High();
32
33         
// update score text
34         score = GameManager.score;
35         txt_score.text =
"Score\n" + score;
36         txt_high.text =
"High Score\n" + high;
37         txt_level.text =
"Level\n" + (GameManager.Level + 1);
38
39     }
40
41
42 }


Use this for initialization

Update is called once per frame

update score text



Gõ tìm kiếm nhanh...